public class Practice2 {
    //https://www.nowcoder.com/practice/c087914fae584da886a0091e877f2c79?tpId=295&tqId=664&ru=/exam/oj&qru=/ta/format-top101/question-ranking&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    //我开始没注意到元素从小到大有序, 由于数据量较小, 采用一个hash维护
    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        ListNode t = new ListNode(-1000);
        t.next = head;
        int[] hash = new int[201];
        ListNode cur = t.next;
        ListNode prev = t;
        while(cur != null){
            if(hash[cur.val + 100]++ != 0){
                prev.next = cur.next;
                cur = cur.next;
            }else{
                prev = cur;
                cur = cur.next;
            }
        }
        return t.next;
    }

    //利用有序的特性

    public ListNode deleteDuplicates (ListNode head) {
        // write code here
        if(head == null || head.next == null){
            return head;
        }
        ListNode cur = head.next;
        ListNode prev = head;
        while(cur != null){
            if(cur.val == prev.val){
                prev.next = cur.next;
            }else{
                prev = cur;
            }
            cur = cur.next;

        }
        return head;

    }
}
